package com.corpgovernment.organization.controller;

import com.corpgovernment.api.organization.dto.EmployeeOpenCardReq;
import com.corpgovernment.api.organization.dto.GetEmployeeOpenCardReq;
import com.corpgovernment.api.organization.dto.GetEmployeeOpenCardRsp;
import com.corpgovernment.common.base.BaseUserInfo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.organization.service.CTripAccountService;
import com.corpgovernment.organization.vo.BindCtripAccountReqVo;
import com.corpgovernment.organization.vo.BindGetVerifyCodeReqVo;
import com.ctrip.corp.obt.generic.event.core.EventCenter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/ctripAccount")
public class CTripAccountController {

    @Autowired
    private CTripAccountService cTripAccountService;

    @Autowired
    private EventCenter eventCenter;

    /**
     * 获取验证码进行散客账号绑定
     * @param request
     * @param baseUserInfo
     * @return
     */
    @PostMapping("/getVerifyCode")
    public JSONResult getVerifyCode(@RequestBody BindGetVerifyCodeReqVo request, BaseUserInfo baseUserInfo){
        request.setSource(baseUserInfo.getSource());
        request.setUid(baseUserInfo.getUid());
        return new JSONResult(cTripAccountService.getVerifyCode(request));
    }

    /**
     * 绑定散客账号
     * @param request
     * @param baseUserInfo
     * @return
     */
    @PostMapping("/bindAccount")
    public JSONResult bindAccount(@RequestBody BindCtripAccountReqVo request, BaseUserInfo baseUserInfo){
        request.setUid(baseUserInfo.getUid());
        return new JSONResult(cTripAccountService.bindAccount(request));
    }

    /**
     * 员工开卡
     * 补偿调用接口
     * 入参有值则按入参进行开卡
     * 入参无数据则全局补偿 检索未开卡得去进行开卡
     * @return
     */
    @PostMapping("/employeeOpenCard")
    public JSONResult employeeOpenCard(@RequestBody EmployeeOpenCardReq request){
        cTripAccountService.employeeOpenCard(request);
        return JSONResult.ok();
    }

    /**
     * 查询员工开卡信息/是否绑定携程账号
     * @return
     */
    @PostMapping("/getEmployeeOpenCardInfo")
    public JSONResult<GetEmployeeOpenCardRsp> getEmployeeOpenCardInfo(@RequestBody GetEmployeeOpenCardReq request){
        return JSONResult.success(cTripAccountService.getEmployeeOpenCardInfo(request));
    }

}